﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using KPIS.GERP.GBMS.IBLL;
using KPIS.GERP.GBMS.MODEL;
using KPIS.GERP.GBMS.DAL;
using KPIS.GERP.GBMS.DALFactory;

namespace KPIS.GERP.GBMS.BLL
{
    public class ExpenseRateDtlsBLL : IExpenseRateDtlsBLL
    {
        private static readonly IExpenseRateDtlsDAL dal = DataAccess.CreateExpenseRateDtls();

        public ExpenseRateDtlsBLL()
        {

        }

        public void Insert(string name, string descr, string rate, string expense)
        {
            double inRate = (rate.Length > 0) ? Convert.ToDouble(rate) : 0;
            int inExpense = (expense.Length > 0) ? Convert.ToInt32(expense) : 0;

            ExpenseRateInfo expRateInfo = new ExpenseRateInfo();
            expRateInfo.Sequence = inExpense;

            ExpenseRateDtlsInfo expRateDtlsInfo = new ExpenseRateDtlsInfo(0, name, descr, "", inRate, expRateInfo, new UserRecordInfo(1, 1));

            int chkError = dal.Insert(expRateDtlsInfo);

            if (chkError == 0)
            {
                 //Error
            }
        }

        public void Update(string seq, string name, string descr, string rate, string expense)
        {
            int inSeq = (seq.Length > 0) ? Convert.ToInt32(seq) : 0;
            double inRate = (rate.Length > 0) ? Convert.ToDouble(rate) : 0;
            int inExpense = (expense.Length > 0) ? Convert.ToInt32(expense) : 0;

            ExpenseRateInfo expRateInfo = new ExpenseRateInfo();
            expRateInfo.Sequence = inExpense;

            ExpenseRateDtlsInfo expRateDtlsInfo = new ExpenseRateDtlsInfo(inSeq, name, descr, "", inRate, expRateInfo, new UserRecordInfo(1, 1));

            int chkError = dal.Update(expRateDtlsInfo);

            if (chkError == 0)
            {
                //Error
            }
        }

        public void Delete(string seq)
        {
            int chkError = dal.Delete(Convert.ToInt32(seq));
        }

        public IList<ExpenseRateDtlsInfo> Search(string seq)
        {
            return Search(seq, "", "", "", "");
        }

        public IList<ExpenseRateDtlsInfo> Search(string seq, string name, string descr, string rate, string expense)
        {
            double inrate = (rate.Length > 0) ? Convert.ToDouble(rate) : 0;
            int inSeq = (seq.Length > 0) ? Convert.ToInt32(seq) : 0;
            int inExpense = (expense.Length > 0) ? Convert.ToInt32(expense) : 0;

            ExpenseRateDtlsInfo expRateDtlsInfo = new ExpenseRateDtlsInfo(inSeq, name, descr, "", inrate, new ExpenseRateInfo(inExpense, "", 0, "", "", "", null, null), new UserRecordInfo(1, 1));

            return dal.Search(expRateDtlsInfo);
        }

        public IList<ExpenseRateDtlsInfo> SearchExpRate(string seq, string name, string descr, string rate, string expense)
        {
            double inrate = (rate.Length > 0) ? Convert.ToDouble(rate) : 0;
            int inSeq = (seq.Length > 0) ? Convert.ToInt32(seq) : 0;
            int inExpense = (expense.Length > 0) ? Convert.ToInt32(expense) : 0;

            ExpenseRateDtlsInfo expRateDtlsInfo = new ExpenseRateDtlsInfo(inSeq, name, descr, "", inrate, new ExpenseRateInfo(inExpense, "", 0, "", "", "", null, null), new UserRecordInfo(1, 1));

            return dal.SearchExpRate(expRateDtlsInfo);
        }

    }
}
